// pages/customer/customer.js
const TAG = "customer"
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
var mCurrentPage = 0;
var mCurrentTabCat = 1;
Page({
    /**
     * 页面的初始数据
     */
    data: {
        //tab
        tabs: ["选项一", "选项二", "选项三"],
        activeIndex: 0,
        sliderOffset: 0,
        sliderLeft: 0,
        //ptr list
        isHideLoadMore: true,
        grid_datas: [
            {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            },
            {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }
        ]
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        mCurrentPage = 0;
        wx.showNavigationBarLoading() //在标题栏中显示加载
        //模拟加载
        setTimeout(function () {
            // complete
            console.log(TAG, "onPullDownRefresh: mCurrentPage = " + mCurrentPage)
            console.log(TAG, "onPullDownRefresh: mCurrentTabCat = " + mCurrentTabCat)
            wx.hideNavigationBarLoading() //完成停止加载
            wx.stopPullDownRefresh() //停止下拉刷新
        }, 1500);
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        self = this
        console.log(TAG, "onReachBottom")
        this.setData({
            isHideLoadMore: false
        })
        setTimeout(function () {
            mCurrentPage++;
            console.log(TAG, "onLoadMore: mCurrentPage = " + mCurrentPage)
            console.log(TAG, "onLoadMore: mCurrentTabCat = " + mCurrentTabCat)

            var tmp = self.data.grid_datas;
            tmp.push({
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            }, {
                url: "https://gitee.com/index/ent_poster/banner_5_1_a.png",
                name: "OSC中国"
            });
            // complete
            self.setData({
                isHideLoadMore: true,
                grid_datas: tmp
            })
        }, 1500);
    },
    onLoad: function () {
        var that = this;
        wx.getSystemInfo({
            success: function (res) {
                console.log(TAG, res)
                that.setData({
                    sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
                    sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
                });
            }
        });
    },
    tabClick: function (e) {
        console.log(e)
        mCurrentPage = 0;
        switch (e.currentTarget.id) {
            case "0":
                mCurrentTabCat = 100;
                break;
            case "1":
                mCurrentTabCat = 101;
                break;
            case "2":
                mCurrentTabCat = 102;
                break;
            default:
                mCurrentTabCat = 100;
        }
        console.log(TAG, "mCurrentTabCat = " + mCurrentTabCat)
        this.setData({
            sliderOffset: e.currentTarget.offsetLeft,
            activeIndex: e.currentTarget.id
        });
    }
})